#pragma once

namespace My {

inline TimeRuler & Timeline::GetTimeRuler()
{
	return m_TimeRuler;
}

inline Navigator & Timeline::GetNavigator()
{
	return m_Navigator;
}

inline ThumbLine & Timeline::GetThumbLine()
{
	return m_ThumbLine;
}

inline Sequence * Timeline::GetSequence() const
{
	return m_pSequence;
}

inline bool Timeline::IsEmpty() const
{
	return GetSequence() == 0 || GetSequence()->IsEmpty();
}

inline int Timeline::GetCurrentFrame() const
{
	return m_CurrentFrame;
}

inline int Timeline::GetGap() const
{
	return m_Gap;
}

inline void Timeline::UpdateCurrentFrame()
{
	if (!IsEmpty())
		GetSequence()->SetCurrentFrame(GetCurrentFrame());
}

inline Span Timeline::GetWorkArea() const
{
	if (IsEmpty())
		return Span(0, 0);
	else
		return Span(m_WorkArea).Offset(GetSequence()->GetStart());
}

inline double Timeline::GetTimeScale() const
{
	return m_TimeScale;
}

inline double Timeline::GetMinTimeScale() const
{
	if (IsEmpty() || GetXPage() <= 0)
		return 1.0;
	return double(GetXPage()) / GetSequence()->GetTimeSpan().Size();
}

inline double Timeline::GetMaxTimeScale() const
{
	return 50.0;
}

inline double Timeline::GetTimeOffset() const
{
	return m_TimeOffset;
}

inline double Timeline::GetTimePage() const
{
	return GetXPage() / GetTimeScale();
}

inline double Timeline::GetTimeRange() const
{
	return GetSequence() == 0 || GetSequence()->IsEmpty() ? 
		0 : GetSequence()->GetDuration();
}

inline int Timeline::GetXRange() const
{
	return int(GetTimeRange() * GetTimeScale());
}

inline int Timeline::GetXOffset() const
{
	if (IsEmpty())
		return 0;
	return int((GetTimeOffset() - GetSequence()->GetStart()) * GetTimeScale());
}

inline void Timeline::OnCurrentFrameChanged()
{
	SetCurrentFrame(GetSequence()->GetCurrentFrame());
}

inline void Timeline::OnWorkAreaChanged()
{
	SetWorkArea(GetSequence()->GetWorkArea());
}
inline void Timeline::SetXOffset(int x)
{
	if (IsEmpty())
		return;
	SetTimeOffset(GetSequence()->GetStart() + x / m_TimeScale);
}

inline double Timeline::XToTime(int x) const
{
	return GetTimeOffset() + GetTimePage() 
		* double(x - m_Gap) 
		/ (GetXPage() - 2 * m_Gap);
}

inline int Timeline::TimeToX(double t) const
{
	return m_Gap + Round((GetXPage() - 2 * m_Gap) 
		* (t - GetTimeOffset()) 
		/ GetTimePage());
}





} // My
